package Swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class keyBorder {
    public static void main (String[] args) {
        JFrame test = new JFrame ("Test");
        test.setBounds (200, 200, 500, 500);
        test.setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);
        Container contentPane = test.getContentPane ();
        contentPane.setLayout (new FlowLayout ());
        //**********************************************
        Squre s = new Squre ();
        s.setBackground (Color.black);
        s.setPreferredSize (new Dimension (100,100));
        test.addKeyListener (new KeyAdapter () {
            @Override
            public void keyPressed (KeyEvent e) {
                int a = e.getKeyCode ();
                if (a == KeyEvent.VK_DOWN) {
                    s.getX ();
                    s.repaint ();
                }
            }
        });
        //**********************************************
        contentPane.add (s);
        test.setVisible (true);
    }
}

class Squre extends JPanel {
    @Override
    public void paintComponents (Graphics g) {
        g.fillOval (this.getX (), this.getY (), 10, 10);
    }
}
